package com.vote.vs.controller;

import com.vote.vs.entity.Subject;
import com.vote.vs.entity.SubjectDto;
import com.vote.vs.service.SubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
@RequestMapping("/subject")
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    @RequestMapping("/subjectList")
    @ResponseBody
    public Object subjectList() {
        List<SubjectDto> subjectDtos = subjectService.subjectList();
        return subjectDtos;
    }

    @RequestMapping("/publishNewVote")
    public String publishVote(Subject subject, String[] options) {
        subjectService.insertSubject(subject, options);


        return "add_success";
    }

}
